import {getToken} from "@/utils/user.js";
import api from "@/api/index.js";
import {closeToast, showLoadingToast} from "vant";

export  function gotoUri(item, uri) {
    if (item.path.indexOf('#/') !== -1) {
        window.location.href = uri.href.replace(uri.origin, `${uri.origin}/#`);
    } else {
        window.location.href = uri.href;
    }
}

export  function  goToWithTmpToken(item){
    let uri = new URL(item.path.replace('#/', ''));
    uri.searchParams.append('redirectUrl', location.href);
    console.log('uri',uri)
    if (getToken()) {
        showLoadingToast('加载中')
        api.getTmpToken().then((res) => {
            if (res.code === '200') {
                uri.searchParams.append('tmpToken', res.data);
                gotoUri(item, uri);
            }
        }).finally(()=>{
            closeToast()
        });
    } else {
        gotoUri(item, uri);
    }
}